<?php
// Check all/uncheck all does not work anymore!!
	session_start();
	require("connect.php");
	$link = connect_APO();
		
	require("check.php");
	is_logged_in();
	is_admin();
	
	require("header+logoutB.php");
	headerL();
	
	$sql="SELECT * FROM `users`";
	$result=mysql_query($sql);
			
	if(!$result){
		die('Error: ' .mysql_error());
	}
		echo "<html>
		<head> 
		<script type='text/javascript'>
			function checkAll(field, value) {
				for (var i=0;i<(document.forms[0].elements[field].length);i++) {
					if(value === 'true'){
						document.forms[0].elements[field][i].checked = true;
					} else {
						document.forms[0].elements[field][i].checked = null;
					}
				} 
			}
		</script>
		</head>	
<body class='main'>

<FONT class='mainFont'>
	<CENTER>
	<!--<p><img src = 'images/apopic.jpg'></p>-->
	<br>
	<br>
	<div class='headerTable'>
		<div id='links'>
			<div id='backLink'> <A href='usersAdmin.php'>Back to Users Administration</A></div>
		</div>
		<b class='b1f'></b><b class='b2f'></b>
		<b class='b3f'></b><b class='b4f'></b>
		<div class='contentf'>
			<div class = 'headerText'>
				Users with pending Midweek Credit:
	 		</div>
	 		<div id='form'>
		 		<div id='heading'>
			 		<b class='name'> Name </b>
			 		<b class='location'> Location(s) </b>
			 		<b class='credit'> Credit </b>
			 		<b class='checkbox'> Grant Credit </b>
		 		</div>
	 		<form id='giveCredit' name='giveCredit' action='submitPending.php' method='post'>";
	  
	while($row = mysql_fetch_array($result)){
		if($row['Pending'] > 0){
			echo "
			<div id='item'>
				<div class='name'>".$row['Fname']." ".$row['Lname']."
				</div>
				<div class='location'>".$row['PendingLocation']."
				</div>
				<div class='credit'>".$row['Pending']."
				</div>
				<div class='checkbox'>
					<input name='credit[]' type='checkbox' value='".$row['ID']."'/>
				</div>
			</div>";
		} else {
			continue;
		}
	}
	  
	  echo "		<div id='buttonContainer'>
		  				<div class='setCheck'>
						  	<a href='#buttonContainer' name='checkAll' onClick=\"checkAll('credit[]', 'true');\">Check All</a> 
						  	<a href='#buttonContainer' name='checkNone' onClick=\"checkAll('credit[]', 'false');\">Uncheck All</a>
						</div>
						<div id='submitStuff'>
							<input name='submitPending' type='submit' class='loginButton' value='Grant Credit' id='pendingSubmit'>
							
							<input name='submitPending' type='submit' class='loginButton' value='Clear Pending Credit' id='pendingSubmit'>
						</div>
					</div>
	  			</form>
	  		</div>
	  	</div>
	  	<b class='b4f'></b><b class='b3f'></b>
		<b class='b2f'></b><b class='b1f'></b>
	</div>
</CENTER>
</FONT>
</body>
</html>";


	require("footer.php");
	footer();
	mysql_close($link);
	
?>